package exec567;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Test2 {
    public static void main(String[] args) {
        File file=new File("student.dat");
        try {
            InputStream inputStream=new FileInputStream(file);
            ObjectInputStream objectInputStream=new ObjectInputStream(inputStream);
            Object list= objectInputStream.readObject();
            if(list instanceof List)
            {
                List<Student> students= (List<Student>) list;
                int diff=0;
                Collections.max(students, new Comparator<Student>() {
                    @Override
                    public int compare(Student o1, Student o2) {
                        int diff=o1.getScore()-o2.getScore();
                        if(diff>0){
                            return 1;
                        }else if(diff<0){
                            return -1;
                        }
                        return 0;
                    }
                });
                System.out.println("最大值为"+diff);
                for(Student s: students){
                    System.out.println(s);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
